package com.hopu.mybatis01.controller;
import com.hopu.mybatis01.mapper.UserMapper1;
import com.hopu.mybatis01.pojo.User1;
import com.hopu.mybatis01.service.IzyService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

    @RestController
    @RequestMapping("user1")
    public class zyController {
        @Resource
        private IzyService izyService;
        private List<User1> list = new ArrayList<User1>();
        private long id = 1;
        @Resource
        private UserMapper1 userMapper1;


        //查询
        @GetMapping
        public List<User1> getUsers(String name, String phone) {
            return izyService.getUsers(name,phone);

        }
        //添加
        @PostMapping
        public String add(@RequestBody User1 user1){
            userMapper1.insert(user1);
            return "添加成功";
        }

        //删除
        @DeleteMapping
        public String remove(long id){
            userMapper1.deleteById(id);//对每个User1检查若他的id等于传入id则做删除操作
            return "删除成功";
        }

        //修改
        @PutMapping
        public String update(@RequestBody User1 user1) {
            userMapper1.update(user1);
            return "修改成功";
        }


    }
